﻿using UnityEngine;
using System.Collections;

public class ReferencePlane2D : MonoBehaviour {
	public Plane2D attachedPlane2D;
	
	Vector3 screenPoint;
	Vector3 offset;
		
	void OnMouseDown()
	{
		//Move the background to its position
		Vector3 scanPos = gameObject.transform.position;
	    screenPoint = Camera.main.WorldToScreenPoint(scanPos);
	    offset = scanPos - Camera.main.ScreenToWorldPoint(
	        new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
	}
	
	void OnMouseDrag()
	{
		Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
 
	    Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
	    transform.position = curPosition;
	}
}
